import { apiClient } from 'axiom-view';

/**
 * 获取用户列表（分页）
 * @param {object} params - 查询参数，例如 { page, page_size, username, email, status }
 * @returns {Promise<ApiResponse_PaginatedResponse_UserVO__>}
 */
export const getUserList = (params) => {
  return apiClient.get('/system/users', { params });
};

/**
 * 获取用户详情
 * @param {string} userId - 用户ID
 * @returns {Promise<ApiResponse_UserVO_>}
 */
export const getUserDetails = (userId) => {
  return apiClient.get(`/system/users/${userId}`);
};

/**
 * 新增用户
 * @param {UserCreateDTO} data - 用户数据
 * @returns {Promise<ApiResponse_UserVO_>}
 */
export const createUser = (data) => {
  return apiClient.post('/system/users', data);
};

/**
 * 修改用户信息
 * @param {string} userId - 用户ID
 * @param {UserUpdateDTO} data - 要更新的用户数据
 * @returns {Promise<ApiResponse_UserVO_>}
 */
export const updateUser = (userId, data) => {
  return apiClient.put(`/system/users/${userId}`, data);
};

/**
 * 删除用户
 * @param {string} userId - 用户ID
 * @returns {Promise<ApiResponse>}
 */
export const deleteUser = (userId) => {
  return apiClient.delete(`/system/users/${userId}`);
};

/**
 * 为用户分配角色
 * @param {string} userId - 用户ID
 * @param {string[]} roleIds - 角色ID列表
 * @returns {Promise<ApiResponse>}
 */
export const assignRolesToUser = (userId, roleIds) => {
  return apiClient.post(`/system/users/${userId}/assign-roles`, { role_ids: roleIds });
};

/**
 * 重置用户密码
 * @param {string} userId - 用户ID
 * @param {UserPasswordResetDTO} data - 新密码数据
 * @returns {Promise<ApiResponse>}
 */
export const resetUserPassword = (userId, data) => {
    return apiClient.put(`/system/users/${userId}/reset-password`, data);
};

/**
 * 启用用户
 * @param {string} userId - 用户ID
 * @returns {Promise<ApiResponse>}
 */
export const enableUser = (userId) => {
  return apiClient.put(`/system/users/${userId}/enable`);
};

/**
 * 禁用用户
 * @param {string} userId - 用户ID
 * @returns {Promise<ApiResponse>}
 */
export const disableUser = (userId) => {
  return apiClient.put(`/system/users/${userId}/disable`);
};

/**
 * 批量删除用户
 * @param {string[]} userIds - 用户ID列表
 * @returns {Promise<ApiResponse>}
 */
export const batchDeleteUsers = (userIds) => {
  return apiClient.delete('/system/users', { data: { ids: userIds } });
}; 